﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace PedesTrainProject.Grid
{
    [Serializable()]
    public class Lane : ISerializable
    {
        private List<Slot> slots = new List<Slot>();
        private Directions direction;
        private bool exit;
        private InFlowFlag inFlow = null;
        public List<Slot> Slots
        {
            get { return slots; }
            set { slots = value; }
        }

        public Directions Direction
        {
            get { return direction; }
            set { direction = value; }
        }

        public bool Exit
        {
            get { return exit; }
            set { exit = value; }
        }

        public InFlowFlag InFlow
        {
            get { return inFlow; }
            set { inFlow = value; }
        }

        
        public Lane()
        {

        }

        public Lane(Directions _direction, bool _exit)
        {
            direction = _direction;

            exit = _exit;
        }

        public void addInFlowFlag(List<KeyValuePair<DateTime, int>> _intervals)
        {
            inFlow = new InFlowFlag(_intervals);
        }

        public void switchDirection()
        {
            if (direction == Directions.East) direction = Directions.North;
            else if (direction == Directions.West) direction = Directions.South;
            else if (direction == Directions.North) direction = Directions.East;
            else if (direction == Directions.South) direction = Directions.West;
        }

        #region Serialize
        public Lane(SerializationInfo info, StreamingContext ctxt)
        {
            this.slots = (List<Slot>)info.GetValue("Slots", typeof(List<Slot>));
            this.direction = (Directions)info.GetValue("Directions", typeof(Directions));
            this.exit = (bool)info.GetValue("Exit", typeof(bool));
            this.inFlow = (InFlowFlag)info.GetValue("InFlow", typeof(InFlowFlag));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("Slots", this.slots);
            info.AddValue("Directions", this.direction);
            info.AddValue("Exit", this.exit);
            info.AddValue("InFlow", this.inFlow);
        }
        #endregion
    }
}
